<?
	include 'inc/conn.php';
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);

	$db = new mysql();
	if(isset($act)){
		if($act=="q"){
			$db->query("SELECT * FROM `mfg_wo` WHERE FLAG=1");
			$num = $db->db_num_rows();
			echo "::Work Order for TE Server to sync\r\n";
			if($num > 0){
				for($i=0; $i<$num; $i++){
					$row = $db->fetch_assoc();
					echo "${row['ID']}|${row['LINE']}|${row['WO']}|${row['PARTNUM']}\r\n";
				}
			}
		}

		if($act=="u" && isset($id)){
			$condition = "ID=".$id;
			$mod_content="FLAG=0";
			$db->update("mfg_wo", $mod_content, $condition);
		}

		if($act=="m" && isset($id) && isset($msg) && isset($line) && isset($partnumber) && isset($workorder)){
			$condition = "ID=".$id;
			$mod_content="FLAG=0";
			$db->update("mfg_wo", $mod_content, $condition);

			$to = "A-TFS-ENG-EE-TE@hd.tongfangpc.com";
			$title = "【预警系统】: $line -> $partnumber - $workorder";

			$Message = "发现该线配置与其他服务器有差别<br /><br />
						<b>差异项目如下:</b> <br />$msg<br />";

			$Message = str_replace("-", "<br />", $Message);

			$headers = "X-Mailer:PHP\n";
			$headers.= "MIME-Version: 1.0\n";
			$headers.= "Content-type:text/html;charset=utf-8\n";
			$headers.= "X-Priority: 1\n";
			$headers.= "From: MFG_MON<MFG_MON@hd.tongfangpc.com>\r\n"; 
			$message = "<html><head><meta charset='utf-8'></head><body>${Message}</body></html>";
			$subject = "${title}";

			$message=wordwrap($message, 70);

			if (mail($to, $subject, $message, $headers)) {
				echo " - 邮件发送成功!";
			} else {
				mail($to, $subject, $message, $headers);
			}
		}
	}
	$db->close();
?>